package mock;

import javax.servlet.http.HttpServletRequest;

import org.jmock.*;

public class MockRequestTest extends MockObjectTestCase {

  public void testMockRequest1() {

    // 构造一个Mock对象
    Mock mock = new Mock(HttpServletRequest.class);

    // 设置要执行的操作，以下设置表示要调用一次HttpServletRequest对象的
    // getParameter方法，传递的参数是"name",期望的返回是"kongxx"

    mock.expects(once()).method("getParameter").with(eq("name")).will(returnValue("kongxx"));

    // 根据Mock对象获取一个HttpServletRequest对象
    HttpServletRequest request = (HttpServletRequest) mock.proxy();

    // 断言调用结果
    assertEquals("kongxx", request.getParameter("name"));

  }
}
